const jwt = require('jsonwebtoken');

module.exports = function () {
    return async function ( req, res, next) {
        console.log(process.env.SecretOrPublicKey)
        let payload = jwt.decode(req.headers.authorization.split(' ')[1], process.env.SecretOrPublicKey);
        if(payload.role === 'admin'){
            await next()
        }else{
            return res.status(401).send({
                success: false,
                message: 'Authorization不足',
            });
        }
    }
}